package cn.psvmc.cxzapi.controller.system;

import cn.psvmc.cxzapi.model.common.DelEntity;
import cn.psvmc.cxzapi.model.common.SearchEntity;
import cn.psvmc.cxzapi.model.system.THelp;
import cn.psvmc.cxzapi.response.Result;
import cn.psvmc.cxzapi.response.ResultGenerator;
import cn.psvmc.cxzapi.service.system.THelpService;
import cn.psvmc.cxzapi.util.ToolUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 帮助中心
 *
 * @Author auto
 * @Date 2024-08-29
 */
@RestController
@RequestMapping("/help")
public class THelpController {

    @Resource
    private THelpService tHelpService;

    /**
     * @Author auto 2024-08-29 新增帮助中心表
     * @Param tHelp 帮助中心表
     * @Return cn.psvmc.cxzapi.response.Result
     */
    @PostMapping("/add")
    public Result add(@RequestBody THelp tHelp) {
        ToolUtils.validation(new Object[]{
                tHelp.getTitle(), "标题", 2
                , tHelp.getContent(), "内容", 2
                , tHelp.getType(), "类型", 1
        });
        int addResult = tHelpService.add(tHelp);
        if (addResult > 0) {
            return ResultGenerator.genSuccessResult("保存成功！");
        }
        return ResultGenerator.genFailResult("保存失败！");
    }

    /**
     * @Author auto 2024-08-29 更新帮助中心表
     * @Param tHelp 帮助中心表模型
     * @Return cn.psvmc.cxzapi.response.Result
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody THelp tHelp) {
        ToolUtils.validation(new Object[]{tHelp.getHelpid(), "id", 1, tHelp.getRversion(), "版本", 1});
        int updateResult = tHelpService.edit(tHelp);
        if (updateResult > 0) {
            return ResultGenerator.genSuccessResult("更新成功！");
        }
        return ResultGenerator.genFailResult("更新失败！");
    }

    /**
     * @Author auto 2024-08-29 删除帮助中心表
     * @Param entity
     * @Return cn.psvmc.cxzapi.response.Result
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody DelEntity entity) {
        Integer id = entity.getId();
        Integer rversion = entity.getRversion();
        ToolUtils.validation(new Object[]{id, "id", 1, rversion, "版本", 1});
        int delResult = tHelpService.delete(id, rversion);
        if (delResult > 0) {
            return ResultGenerator.genSuccessResult("删除成功！");
        }
        return ResultGenerator.genFailResult("删除失败！");
    }

    /**
     * @Author auto 2024-08-29 查询帮助中心表列表
     * @Param entity 分页查询通用实体类
     * @Return cn.psvmc.cxzapi.response.Result
     */
    @PostMapping("/list")
    public Result list(@RequestBody SearchEntity entity) {
        return ResultGenerator.genSuccessResult("查询成功！", tHelpService.list(entity));
    }
}
